<%--
  Created by IntelliJ IDEA.
  User: ZXW
  Date: 2022/4/26
  Time: 21:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>



      <div id="page_nav">
<%--大于首页，才显示--%>
<c:if test="${sessionScope.page.pageNo>1}">
          <a href="${ sessionScope.page.url }&pageNo=1&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">首页</a>
          <a href="${ sessionScope.page.url }&pageNo=${ sessionScope.page.pageNo-1 }&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">上一页</a>
</c:if>

    <%--页码输出的开始--%>
    <c:choose>
        <%--情况 1：如果总页码小于等于 5 的情况，页码的范围是：1-总页码--%>
        <c:when test="${sessionScope.page.pageTotal<=5}">
            <c:set var="begin" value="1" />
            <c:set var="end" value="${sessionScope.page.pageTotal}" />

        </c:when>

        <c:when test="${sessionScope.page.pageTotal>5}">
            <c:choose>
                <%--小情况 1：当前页码为前面 3 个：1，2，3 的情况，页码范围是：1-5.--%>
                <c:when test="${sessionScope.page.pageNo<=3}">
                    <c:set var="begin" value="1" />
                    <c:set var="end" value="5" />


                </c:when>
                <%--小情况 2：当前页码为最后 3 个，8，9，10，页码范围是：总页码减 4 - 总页码--%>
                <c:when test="${sessionScope.page.pageNo>sessionScope.page.pageTotal-3}">
                    <c:set var="begin" value="${sessionScope.page.pageTotal-4}" />
                    <c:set var="end" value="${sessionScope.page.pageTotal}" />


                </c:when>
                <%--小情况 3：4，5，6，7，页码范围是：当前页码减 2 - 当前页码加 2--%>
                <c:otherwise>
                    <c:set var="begin" value="${sessionScope.page.pageNo-2}" />
                    <c:set var="end" value="${sessionScope.page.pageNo+2}" />

                </c:otherwise>
            </c:choose>
        </c:when>
    </c:choose>


    <c:forEach begin="${begin}" end="${end}" var="i">
        <c:if test="${i==sessionScope.page.pageNo}">
            【${i}】
        </c:if>

        <c:if test="${i!=sessionScope.page.pageNo}">
<%--            <a href="${ sessionScope.page.url }&pageNo=${i}">${i}</a>--%>
            <a href="${ sessionScope.page.url }&pageNo=${i}&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">${i}</a>
        </c:if>
    </c:forEach>


    <%--页码输出的结束--%>
<%-- 如果已经 是最后一页，则不显示下一页，末页 --%>
    <c:if test="${sessionScope.page.pageNo< sessionScope.page.pageTotal}">
<%--          <a href="${ sessionScope.page.url }&pageNo=${ sessionScope.page.pageNo+1 }&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">下一页</a>--%>
<%--          <a href="${ sessionScope.page.url }&pageNo=${ sessionScope.page.pageTotal}&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">末页</a>--%>
          <a href="${ sessionScope.page.url }&pageNo=${ sessionScope.page.pageNo+1 }&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">下一页</a>
          <a href="${ sessionScope.page.url }&pageNo=${ sessionScope.page.pageTotal}&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>">末页</a>
    </c:if>
    共${ sessionScope.page.pageTotal }页，${ sessionScope.page.pageTotalCount }条记录
    到第<input value="${param.pageNo}" name="pn" id="pn_input"/>页
    <input id="searchPageBtn" type="button" value="确定">
    <script type="text/javascript">

        $(function (){
            $("#searchPageBtn").click(function (){
                var pageNo = $("#pn_input").val();

                <%--if(pageNo<1||pageNo>${sessionScope.page.pageTotal}){--%>
                <%--    alert("请输入正常页码");--%>
                <%--    return false;--%>
                <%--}else{--%>
                    <%--location.href="${pageScope.basePath}${ sessionScope.page.url }&pageNo="+pageNo;--%>
                    location.href = "${pageScope.basePath}${sessionScope.page.url }&pageNo=" + pageNo+"&username=<c:if test="${sessionScope.self==false }">${sessionScope.queryUserName}</c:if><c:if test="${sessionScope.self==true}">${sessionScope.user.username}</c:if>";
                // }

            });
        });


    </script>




      </div>